﻿#region Header
// Copyright 2007-2011, Jerónimo Milea
// 
// This file is part of NetJsWire.
// 
//     NetJsWire is free software: you can redistribute it and/or modify
//     it under the terms of the GNU General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
// 
//     NetJsWire is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU General Public License for more details.
// 
//     You should have received a copy of the GNU General Public License
//     along with NetJsWire.  If not, see <http://www.gnu.org/licenses/>.
#endregion

using System.ComponentModel;
using NetJsWire.JsonRpcHandler;
using NetJsWire.JsonRpcHandler.Attributes;
using NetJsWire.JsonRpcHandler.Util;
using NetJsWire.Widgets.Config;
using Newtonsoft.Json;

namespace NetJsWire.Widgets.Data
{
    [Renderer( typeof( Renderers.Data.ArrayStore ) )]
    [JsonObject( MemberSerialization = MemberSerialization.OptIn )]
    public class ArrayStore : Store
    {
        private readonly IRenderer _renderer;
        private IConfigOptions _configOptions;

        public ArrayStore()
            : this( null )
        {
        }

        ///<summary>
        ///  Initializes a new instance of ArrayStore and adds it to the Container.
        ///</summary>
        ///<param name = "container">The container to add this component.</param>
        public ArrayStore( IContainer container )
        {
            if ( container != null )
                container.Add( this );

            _renderer = Helper.GetRenderer( this );
        }

        [Browsable( false )]
        public override IRenderer Renderer
        {
            get { return _renderer; }
        }

        [RefreshProperties( RefreshProperties.All )]
        [DesignerSerializationVisibility( DesignerSerializationVisibility.Content )]
        [Category( "Config" )]
        [JsonProperty]
        public override IConfigOptions ConfigOptions
        {
            get { return _configOptions ?? ( _configOptions = new ArrayStoreConfigOptions( this ) ); }
        }
    }
}
